#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=20;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn][maxn];
LL n,m;
bool solve(string s){
    for(LL i=1;i<=n;i++){
        LL num=0;
        for(LL j=1;j<=m;j++){
            if(s[j]!=str[i][j]){
                num++;
            }
        }
        if(num>1) return false;
    }
    return true;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    cin>>n>>m;
    for(LL i=1;i<=n;i++){
        cin>>(str[i]+1);
    }
    bool flag=1;string ans="";
    for(LL i=1;flag==1&&i<=m;i++){
        LL len=strlen(str[1]+1);
        string s=" ";
        for(LL j=1;j<=m;j++) s+=str[1][j];
        for(LL j=1;j<=26;j++){
            s[i]=char('a'+j-1);
            if(solve(s)==true){
                flag=0;
                ans=s;
                break;
            }
        }
    }
    if(flag==1){
        cout<<"-1"<<"\n";
    }
    else{
        for(LL i=1;i<ans.size();i++) cout<<ans[i];
        cout<<"\n";
    }
  }
return 0;
}
